package com.lq.leetcode;

/**
 * Main11
 *
 * @author qingqing
 * @date 2025/3/2
 */

public class Main11 {
    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int maxArea = 0;
        while (left < right) {
            maxArea = Math.max(Math.min(height[left], height[right]) * (right - left), maxArea);
            int x = 1;
            if (height[left] > height[right]) {
                while (right - x >= left && height[right - x] < height[right]) {
                    x++;
                }
                right = right - x;
            } else {
                while (left + x <= right && height[left + x] < height[left]) {
                    x++;
                }
                left = left + x;
            }
        }
        return maxArea;
    }
}
